package com.example.mall.web.controller;

import com.example.mall.domain.InventoryAudits;
import com.example.mall.dto.InventoryAuditsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.InventoryAuditsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IInventoryAuditsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/inventoryAudits")
public class InventoryAuditsController {

    @Autowired
    public IInventoryAuditsService inventoryAuditsService;

    /**
     * 分页查询库存盘点表信息
     * @param inventoryAuditsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询库存盘点表信息",notes = "分页查询库存盘点表信息",httpMethod = "GET")
    public JSONResult queryPage(InventoryAuditsQuery inventoryAuditsQuery){
        PageDTO<InventoryAuditsDto> inventoryAuditsDtoPageDTO = inventoryAuditsService.queryPage(inventoryAuditsQuery);
        return JSONResult.success("查询成功",inventoryAuditsDtoPageDTO);
    }

    /**
     * 根据id查询库存盘点表信息
     * @param auditId
     * @return
     */
    @GetMapping("query/{auditId}")
    @ApiOperation(value = "根据id查询库存盘点表信息",notes = "根据id查询库存盘点表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("auditId")Long auditId){
        //1.根据id查询用户信息
        if (auditId == null){
            throw new GlobalCustomerException(ErrorEnumCode.AUDITID_NOT_ID);
        }
        InventoryAudits inventoryAudits = inventoryAuditsService.getById(auditId);
        return JSONResult.success("查询成功",inventoryAudits);
    }

    /**
     * 根据id查询库存盘点表信息
     * @param auditId
     * @return
     */
    @GetMapping("queryInventoryAuditsById/{auditId}")
    @ApiOperation(value = "根据id查询库存盘点表信息",notes = "根据id查询库存盘点表信息",httpMethod = "GET")
    public JSONResult queryInventoryAuditsById(@PathVariable("auditId")Long auditId){
        //1.根据id查询用户信息
        if (auditId == null){
            throw new GlobalCustomerException(ErrorEnumCode.AUDITID_NOT_ID);
        }
        InventoryAudits inventoryAudits = inventoryAuditsService.queryInventoryAuditsById(auditId);
        return JSONResult.success("查询成功",inventoryAudits);
    }

    /**
     * 查询全部库存盘点表信息
     * @param
     * @return
     */
    @GetMapping("queryInventoryAuditsList")
    @ApiOperation(value = "查询全部库存盘点表信息",notes = "查询全部库存盘点表信息",httpMethod = "GET")
    public JSONResult queryInventoryAuditsList(){
        List<InventoryAudits> logins = inventoryAuditsService.queryInventoryAuditsList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增库存盘点表
     * @param inventoryAuditsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增库存盘点表",notes = "新增库存盘点表",httpMethod = "POST")
    public JSONResult insert(@RequestBody InventoryAuditsDto inventoryAuditsDto){
        inventoryAuditsService.insert(inventoryAuditsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改库存盘点表信息
     * @param inventoryAuditsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改库存盘点表信息",notes = "修改库存盘点表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody InventoryAuditsDto inventoryAuditsDto){
        inventoryAuditsService.update(inventoryAuditsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除库存盘点表信息
     * @param auditId
     * @return
     */
    @PostMapping("delete/{auditId}")
    @ApiOperation(value = "删除库存盘点表信息",notes = "删除库存盘点表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("auditId") Long auditId) {
        inventoryAuditsService.delete(auditId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除库存盘点表信息
     * @param auditIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除库存盘点表信息",notes = "批量删除库存盘点表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> auditIds) {
        inventoryAuditsService.deleteBatch(auditIds);
        return JSONResult.success("批量删除成功");
    }
}
